<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of sms_order
 *
 * @author enjaz1
 */
class sms_order extends admin_controller {

    //put your code here
    //put your code here
    public function __construct() {
        parent::__construct();
        $this->load->model('admin/sms_order_model', 'sms_order');
        $this->load->library('sms');
    }

    public function index($offset = false) {
        $limit = metohd_get_uri('dblimit', ADMIN_LIMIT);
        $count = $this->sms_order->filter(true);
        $this->pass['count'] = $count;
        $this->pass['limit'] = $limit;
        $this->pass['result'] = $this->sms_order->filter(FALSE, $offset);
        $this->pass['pagination'] = $this->admin_pagination('index', $count, $limit);
        $this->themes->render('sms/order', $this->pass);
    }

    public function all($param = false) {
        $id = $this->input->post('id');
        $action = $this->input->post('doaction');
        $this->empty_id_actionall($id);
        $this->empty_doaction($action);
        if ($action == 'delete') {
            $this->sms_order->delete(array('id' => $id),false,true);
        } elseif ($action == 'confirm') {
            $this->sms_order->save(array('confirm' => 'YES','confirm_date'=>date('Y-m-d H:i:s')), array( 'id' => $id), true);
            $update_user_blance=$this->sms_order->get(array('id'=>$id),'result');
            // add new blance to user
            foreach ($update_user_blance as $value) {
                $this->sms->add_balance($value->msg_num, $value->user_id);
            }

            $this->themes->set_message(array('url' => __CLASS__ . '/index'));
        }
        $this->themes->set_message(array('url' => __CLASS__ . '/index'));
    }
    
    public function view($id=false) {
       $order=$this->sms_order->is_found(array('id'=>$id),array(),FALSE,__CLASS__) ;
       $this->pass['bank_transfers'] = get_bank_transfers($id,'row' ,'new_sms_order');
       $this->pass['result'] = $order;
       $this->themes->render('sms/view', $this->pass);
    }

}

?>
